//
//  Created by Flutter on 2021/4/12.
//

import Coder
import Foundation

public protocol CodableStorable: Storable, Codable {}

public extension CodableStorable {
    init?(data: Data) {
        do {
            let object: Self = try JSONCoder.decode(data: data)
            self = object
        } catch { return nil }
    }

    var toData: Data {
        do {
            let data = try JSONCoder.encode(object: self)
            return data
        } catch {
            return Data()
        }
    }
}

